package net.lab1024.sa.admin.module.business.template.controller;

import net.lab1024.sa.admin.module.business.template.domain.entity.QuotationTemplateEntity;
import net.lab1024.sa.admin.module.business.template.domain.form.QuotationTemplateAddForm;
import net.lab1024.sa.admin.module.business.template.domain.form.QuotationTemplateQueryForm;
import net.lab1024.sa.admin.module.business.template.domain.form.QuotationTemplateUpdateForm;
import net.lab1024.sa.admin.module.business.template.domain.vo.QuotationTemplateDetailVO;
import net.lab1024.sa.admin.module.business.template.domain.vo.QuotationTemplateItemsVO;
import net.lab1024.sa.admin.module.business.template.domain.vo.QuotationTemplateVO;
import net.lab1024.sa.admin.module.business.template.service.QuotationTemplateService;
import net.lab1024.sa.base.common.domain.ValidateList;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;

import java.util.List;

/**
 * 报价单模版 Controller
 *
 * @Author zzx
 * @Date 2025-08-06 11:03:50
 * @Copyright zzx
 */

@RestController
@Tag(name = "报价单模版")
public class QuotationTemplateController {

    @Resource
    private QuotationTemplateService quotationTemplateService;

    @Operation(summary = "分页查询 @author zzx")
    @PostMapping("/quotationTemplate/queryPage")
    @SaCheckPermission("quotationTemplate:query")
    public ResponseDTO<PageResult<QuotationTemplateVO>> queryPage(@RequestBody @Valid QuotationTemplateQueryForm queryForm) {
        return ResponseDTO.ok(quotationTemplateService.queryPage(queryForm));
    }
    @Operation(summary = "分页查询 @author zzx")
    @PostMapping("/quotationTemplate/queryAll")
    @SaCheckPermission("quotationTemplate:queryAll")
    public ResponseDTO<List<QuotationTemplateVO>> queryAll(@RequestBody @Valid QuotationTemplateEntity queryForm) {
        return ResponseDTO.ok(quotationTemplateService.queryAll(queryForm));
    }

    @Operation(summary = "通过模版id查询详情 @author zzx")
    @GetMapping("/quotationTemplate/queryItemsById/{templateId}")
    @SaCheckPermission("quotationTemplate:queryItems")
    public ResponseDTO<List<QuotationTemplateItemsVO>> queryDetailById(@PathVariable Long templateId) {
        return quotationTemplateService.queryItemsById(templateId);
    }

    @Operation(summary = "更新明细 @author zzx")
    @PostMapping("/quotationTemplate/editItems")
    @SaCheckPermission("quotationTemplate:editItems")
    public ResponseDTO<String> add(@RequestBody @Valid QuotationTemplateDetailVO addForm) {
        return quotationTemplateService.addOrUpdate(addForm);
    }

    @Operation(summary = "添加 @author zzx")
    @PostMapping("/quotationTemplate/add")
    @SaCheckPermission("quotationTemplate:add")
    public ResponseDTO<String> add(@RequestBody @Valid QuotationTemplateAddForm addForm) {
        return quotationTemplateService.add(addForm);
    }

    @Operation(summary = "更新 @author zzx")
    @PostMapping("/quotationTemplate/update")
    @SaCheckPermission("quotationTemplate:update")
    public ResponseDTO<String> update(@RequestBody @Valid QuotationTemplateUpdateForm updateForm) {
        return quotationTemplateService.update(updateForm);
    }

    @Operation(summary = "批量删除 @author zzx")
    @PostMapping("/quotationTemplate/batchDelete")
    @SaCheckPermission("quotationTemplate:delete")
    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<Long> idList) {
        return quotationTemplateService.batchDelete(idList);
    }

    @Operation(summary = "单个删除 @author zzx")
    @GetMapping("/quotationTemplate/delete/{templateId}")
    @SaCheckPermission("quotationTemplate:delete")
    public ResponseDTO<String> batchDelete(@PathVariable Long templateId) {
        return quotationTemplateService.delete(templateId);
    }
}
